﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class NewUser : System.Web.UI.Page
{
    MyDataDataContext db = new MyDataDataContext();
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    public void Insert(string name, string password, string phone, string address, string qq, string sex, string studentNum)
    {
        string str = System.Guid.NewGuid().ToString("N");//生成唯一的标识码
        string Pic = "https://img2.baidu.com/it/u=3717120934,3932520698&fm=26&fmt=auto&gp=0.jpg";
        User customer = new User
        {
            UserID = str,
            UserPicture = Pic,
            UserNickname = name,
            UserPwd = password,
            UserPhone = phone,
            UserAddress = address,
            QQ = qq,
            UserSex = sex,
            StudentNumber = studentNum,
            Start = 5.0,
            StartNumber = 1
        };
        db.User.InsertOnSubmit(customer);
        db.SubmitChanges();

    }
    protected void BtnNewUser_Click(object sender, EventArgs e)
    {
        //basic(sender, e);
        User user= (from c in db.User
                    where c.UserNickname == txtName.Text && c.UserPhone== txtNum.Text
                    select c).FirstOrDefault();
        if(user!=null)
        {
            lblMsg.Text = "用户名已存在！";
        }
        else
        {
            Insert(txtName.Text, txtPwd.Text, txtNum.Text, txtAddress.Text, txtQQ.Text, man.Text, stuNum.Text);
            Response.Redirect("Login.aspx?name=" + txtName.Text);
        }        

    }
    
}